#import "UITextView+Extension.h"
#import <objc/runtime.h>
static const char *kPlaceholderKey = "kPlaceholderKey";
static const char *kPlaceholderLabelKey = "kPlaceholderLabelKey";
@implementation UITextView (Extension)
+ (void)load {
    Method setFontMethod = class_getInstanceMethod(self, @selector(setFont:));
    Method was_setFontMethod = class_getInstanceMethod(self, @selector(was_setFont:));
    method_exchangeImplementations(setFontMethod, was_setFontMethod);
}
- (void)was_setFont:(UIFont *)font{
    [self was_setFont:font];
    if (self.placeholderLabel != nil) {
        self.placeholderLabel.font = font;
    }
}
- (UILabel *)placeholderLabel{
    return objc_getAssociatedObject(self, kPlaceholderLabelKey);
}
- (void)setPlaceholderLabel:(UILabel *)placeholderLabel{
    objc_setAssociatedObject(self, kPlaceholderLabelKey, placeholderLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSString *)placeholder{
    return objc_getAssociatedObject(self, kPlaceholderKey);
}
- (void)was_setPlaceholderWithText:(NSString *)placeholder Color:(UIColor *)color{
    objc_setAssociatedObject(self, kPlaceholderKey, placeholder, OBJC_ASSOCIATION_COPY_NONATOMIC);
    UILabel *label = [[UILabel alloc] init];
    label.text = placeholder;
    label.textColor = color;
    label.numberOfLines = 0;
    label.frame = CGRectMake(5, 6, self.frame.size.width, self.frame.size.height);
    [label sizeToFit];
    [self addSubview:label];
    self.placeholderLabel = label;
    self.delegate = self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.placeholderLabel.frame = CGRectMake(5, 6, self.frame.size.width, self.frame.size.height);
    [self.placeholderLabel sizeToFit];
    self.placeholderLabel.hidden = !(self.text.length == 0);
}
- (void)textViewDidChange:(UITextView *)textView{
    self.placeholderLabel.hidden = !(self.text.length == 0);
}
@end
